﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using VSLT_ReportingEngine;
using ExcelAddinDialogBoxes;
using System.Data;


namespace ExcelLoadTestReporting
{
    public partial class ExcelRibbon1
    {
        ReportingEngine re;
        private static string reportingEngineVersion = "6.0.0.1 Beta";
        private bool reportingEngineIsUpToDate = false;

        private void ExcelRibbon1_Load(object sender, RibbonUIEventArgs e)
        {
            // Do we have a SQL string?
            if (Properties.Settings.Default.sqlConn.Length != 0)
            {
                // Create reporting engine
                re = new ReportingEngine(Properties.Settings.Default.sqlConn, reportingEngineVersion);

                if (Properties.Settings.Default.checkDbAtStartup)
                {
                    reportingEngineIsUpToDate = re.GetReportingEngineVersion(reportingEngineVersion);
                }
            }
            else
            {
                btnConfigDb.Enabled = false;
            }
            //UpdateRibbonItemsBasedOnSettings();
            
        }

        private void UpdateRibbonItemsBasedOnSettings()
        {
            if (reportingEngineIsUpToDate)
            {
                lblDbStatus.Label = Properties.Resources.DbCheckSuccessful;
                btnGetRuns.Enabled = true;
                
            }
            else
            {
                lblDbStatus.Label = Properties.Resources.DbCheckNotSuccessful;
                btnGetRuns.Enabled = false;
            }
        }

        private void btnConfigureConnection_Click(object sender, RibbonControlEventArgs e)
        {

        }

        private void btnConfigDb_Click(object sender, RibbonControlEventArgs e)
        {

        }

        private void btnGetRuns_Click(object sender, RibbonControlEventArgs e)
        {
            //GetRuns runs = new GetRuns();
            DataTable runsListDataTable = new DataTable();
            runsListDataTable = re.GetListOfCompletedRuns();
             
        }
    }
}
